<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="用户标识用户表中的流水号(数字0：未插入)" prop="userId">
        <el-input v-model="dataForm.userId" placeholder="用户标识用户表中的流水号(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="地址名称(字符串空：未插入)" prop="addressName">
        <el-input v-model="dataForm.addressName" placeholder="地址名称(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人名字(字符串空：未插入)" prop="consignee">
        <el-input v-model="dataForm.consignee" placeholder="收货人名字(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的电话(字符串空：未插入)" prop="tel">
        <el-input v-model="dataForm.tel" placeholder="收货人的电话(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的手机号(字符串空：未插入)" prop="mobile">
        <el-input v-model="dataForm.mobile" placeholder="收货人的手机号(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货地址的标志性建筑名(字符串空：未插入)" prop="signBuilding">
        <el-input v-model="dataForm.signBuilding" placeholder="收货地址的标志性建筑名(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的最佳收货时间(字符串空：未插入)" prop="bestTime">
        <el-input v-model="dataForm.bestTime" placeholder="收货人的最佳收货时间(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的详细地址(字符串空：未插入)" prop="address">
        <el-input v-model="dataForm.address" placeholder="收货人的详细地址(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的国家(数字0：未插入)" prop="country">
        <el-input v-model="dataForm.country" placeholder="收货人的国家(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的省份(数字0：未插入)" prop="province">
        <el-input v-model="dataForm.province" placeholder="收货人的省份(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人城市(数字0：未插入)" prop="city">
        <el-input v-model="dataForm.city" placeholder="收货人城市(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的地区(数字0：未插入)" prop="district">
        <el-input v-model="dataForm.district" placeholder="收货人的地区(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的邮编(字符串空：未插入)" prop="zipcode">
        <el-input v-model="dataForm.zipcode" placeholder="收货人的邮编(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人邮箱(字符串空：未插入)" prop="email">
        <el-input v-model="dataForm.email" placeholder="收货人邮箱(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否启用即是否默认地址(数字0：未插入，1.未启用,2：启用，)" prop="enabled">
        <el-input v-model="dataForm.enabled" placeholder="是否启用即是否默认地址(数字0：未插入，1.未启用,2：启用，)"></el-input>
      </el-form-item>
      <el-form-item label="操作员(字符串空：未插入)" prop="operator">
        <el-input v-model="dataForm.operator" placeholder="操作员(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="创建即上传时间(数字0：未插入)" prop="createUtc">
        <el-input v-model="dataForm.createUtc" placeholder="创建即上传时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="修改即更新时间(数字0：未插入)" prop="modifyUtc">
        <el-input v-model="dataForm.modifyUtc" placeholder="修改即更新时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否删除(数字0：未插入，1.未删除,2：删除，)" prop="isDeleted">
        <el-input v-model="dataForm.isDeleted" placeholder="是否删除(数字0：未插入，1.未删除,2：删除，)"></el-input>
      </el-form-item>
      <el-form-item label="版本号(数字0：未插入)" prop="version">
        <el-input v-model="dataForm.version" placeholder="版本号(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import API from '@/api'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userId: '',
          addressName: '',
          consignee: '',
          tel: '',
          mobile: '',
          signBuilding: '',
          bestTime: '',
          address: '',
          country: '',
          province: '',
          city: '',
          district: '',
          zipcode: '',
          email: '',
          enabled: '',
          operator: '',
          createUtc: '',
          modifyUtc: '',
          isDeleted: '',
          version: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户标识用户表中的流水号(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          addressName: [
            { required: true, message: '地址名称(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          consignee: [
            { required: true, message: '收货人名字(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          tel: [
            { required: true, message: '收货人的电话(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          mobile: [
            { required: true, message: '收货人的手机号(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          signBuilding: [
            { required: true, message: '收货地址的标志性建筑名(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          bestTime: [
            { required: true, message: '收货人的最佳收货时间(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '收货人的详细地址(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          country: [
            { required: true, message: '收货人的国家(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '收货人的省份(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '收货人城市(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          district: [
            { required: true, message: '收货人的地区(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          zipcode: [
            { required: true, message: '收货人的邮编(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          email: [
            { required: true, message: '收货人邮箱(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          enabled: [
            { required: true, message: '是否启用即是否默认地址(数字0：未插入，1.未启用,2：启用，)不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '操作员(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          createUtc: [
            { required: true, message: '创建即上传时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          modifyUtc: [
            { required: true, message: '修改即更新时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(数字0：未插入，1.未删除,2：删除，)不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            API.upkuseraddress.info(this.dataForm.id).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.upkuseraddress.userId
                this.dataForm.addressName = data.upkuseraddress.addressName
                this.dataForm.consignee = data.upkuseraddress.consignee
                this.dataForm.tel = data.upkuseraddress.tel
                this.dataForm.mobile = data.upkuseraddress.mobile
                this.dataForm.signBuilding = data.upkuseraddress.signBuilding
                this.dataForm.bestTime = data.upkuseraddress.bestTime
                this.dataForm.address = data.upkuseraddress.address
                this.dataForm.country = data.upkuseraddress.country
                this.dataForm.province = data.upkuseraddress.province
                this.dataForm.city = data.upkuseraddress.city
                this.dataForm.district = data.upkuseraddress.district
                this.dataForm.zipcode = data.upkuseraddress.zipcode
                this.dataForm.email = data.upkuseraddress.email
                this.dataForm.enabled = data.upkuseraddress.enabled
                this.dataForm.operator = data.upkuseraddress.operator
                this.dataForm.createUtc = data.upkuseraddress.createUtc
                this.dataForm.modifyUtc = data.upkuseraddress.modifyUtc
                this.dataForm.isDeleted = data.upkuseraddress.isDeleted
                this.dataForm.version = data.upkuseraddress.version
                this.dataForm.createTime = data.upkuseraddress.createTime
                this.dataForm.updateTime = data.upkuseraddress.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            var params = {
              'id': this.dataForm.id || undefined,
              'userId': this.dataForm.userId,
              'addressName': this.dataForm.addressName,
              'consignee': this.dataForm.consignee,
              'tel': this.dataForm.tel,
              'mobile': this.dataForm.mobile,
              'signBuilding': this.dataForm.signBuilding,
              'bestTime': this.dataForm.bestTime,
              'address': this.dataForm.address,
              'country': this.dataForm.country,
              'province': this.dataForm.province,
              'city': this.dataForm.city,
              'district': this.dataForm.district,
              'zipcode': this.dataForm.zipcode,
              'email': this.dataForm.email,
              'enabled': this.dataForm.enabled,
              'operator': this.dataForm.operator,
              'createUtc': this.dataForm.createUtc,
              'modifyUtc': this.dataForm.modifyUtc,
              'isDeleted': this.dataForm.isDeleted,
              'version': this.dataForm.version,
              'createTime': this.dataForm.createTime,
              'updateTime': this.dataForm.updateTime
            }
            var tick = !this.dataForm.id ? API.upkuseraddress.add(params) : API.upkuseraddress.update(params)
            tick.then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
